import { apiWrapper } from '@/utils/request'

// ========================= 用户API (/User) =========================
export const userApi = {
  // 用户登录
  login: (data) => apiWrapper.post('/User/user/login', data),

  // 用户注册
  register: (data) => apiWrapper.post('/User/user/register', data),

  // 获取用户信息
  getUserInfo: () => apiWrapper.get('/User/user/userInfo'),

  // 更新用户个人资料
  updateProfile: (data) => apiWrapper.put('/User/user/updateProfile', data),

  // 获取用户银行卡列表
  getUserCards: () => apiWrapper.get('/User/user/cards'),

  // 分页查询用户交易记录
  pageTradeUser: (data, begin, end) => {
    const params = new URLSearchParams()
    if (begin) params.append('begin', begin)
    if (end) params.append('end', end)
    const url = `/User/pageTradeUser${params.toString() ? '?' + params.toString() : ''}`
    return apiWrapper.post(url, data)
  },

  // 上传头像
  uploadImage: (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return apiWrapper.post('/User/uploadImage', formData, {
      headers: { 'Content-Type': 'multipart/form-data' },
    })
  },
}

// ========================= 管理员客户管理API (/Admin/customer) =========================
export const adminCustomerApi = {
  // 管理员登录
  login: (data) => apiWrapper.post('/Admin/customer/login', data),

  // 获取管理员信息
  getAdminInfo: () => apiWrapper.get('/Admin/customer/getAdminInfo'),

  // 新增客户
  addCustomer: (data) => apiWrapper.post('/Admin/customer/addCustomer', data),

  // 更新客户信息
  updateCustomer: (data) => apiWrapper.put('/Admin/customer/updateCustomer', data),

  // 删除客户
  deleteCustomer: (id) => apiWrapper.delete(`/Admin/customer/deleteCustomer/${id}`),

  // 分页查询客户
  pageCustomer: (data, begin, end) => {
    const params = new URLSearchParams()
    if (begin) params.append('begin', begin)
    if (end) params.append('end', end)
    const url = `/Admin/customer/pageCustomer${params.toString() ? '?' + params.toString() : ''}`
    return apiWrapper.post(url, data)
  },

  // 上传图片
  uploadImage: (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return apiWrapper.post('/Admin/customer/uploadImage', formData, {
      headers: { 'Content-Type': 'multipart/form-data' },
    })
  },
}

// 兼容旧版本的导出
export const userLogin = userApi.login
export const adminLogin = adminCustomerApi.login
export const getUserInfo = userApi.getUserInfo 